/************************************************************************
                        AuthenticationManager.h.cpp - Copyright asaf
*/
#include "AuthenticationManager.h"
#include "Interface.h"
// Ctor/dtor
AuthenticationManager::AuthenticationManager (Interface &t_ifc):m_ifc(t_ifc) {}
AuthenticationManager::~AuthenticationManager ( ) { }

bool AuthenticationManager::checkPermissions (const Request &request)   {
	string s;
	RequestData *requestdata;
	if(m_ifc.getUserPermissionLevel()==ADMINISTRATOR)return true;
	switch (request.getRequestType())
	{
	case LOGIN:
		return true;
	case LOGOUT :
		return true;
	case ADD_PERSON :
		if(m_ifc.getUserPermissionLevel()==NONE)return true;
		return true;
	case ADD_COURSE :
		return false;
	case DELETE_PERSON :
		return false;
	case DELETE_COURSE :
		return false;
	case EDIT_PERSON :
		if (m_ifc.getLoggedUserId()==request.getParameter("ID"))return true;
		return false;
	case REGISTER_STUDENT_COURSE :
		requestdata=(RequestData *)&request;
		s=requestdata->getParameter("StudentID");
		if ((m_ifc.getUserPermissionLevel()==STUDENT)&&
			(m_ifc.getLoggedUserId()==requestdata->getParameter("StudentID")))
			return true;
		return false;
	case ASSIGN_COURSE_LECTURER :
		return false;
	case GET_ALL_COURSE :
		return true;
	case GET_COURSE_DATA :
		return true;
	case GET_PERSON_DATA :
		if (m_ifc.getLoggedUserId()==request.getParameter("ID"))return true;
		return false;
	case GET_COURSES_FOR_SEMESTER :
		return true;
	default:
		return false;
	}
	
}